package cn.cjxy.demo;


import cn.cjxy.domain.Account;
import cn.cjxy.mapper.AccountMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.util.List;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01 {

    @Test
    public void test1() throws Exception{

        SqlSessionFactory factory = 
            new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("SqlMapConfig.xml"));

        // 获取Session
        SqlSession session = factory.openSession();

        // 获取Mapper
        AccountMapper accountMapper = session.getMapper(AccountMapper.class);

        List<Account> userList = accountMapper.findAll();

        for (Account account : userList) {
            System.out.println(account);
        }

        session.close();
    }
}